/**
 * 作者：陈文斌 on 2019/1/4.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/main_scoped_model.dart';
import 'package:crm/component/ClientManager/client_manager_tabs_section.dart';
import 'package:crm/component/ClientManager/client_manager_list_view_section.dart';
import 'package:crm/component/ClientManager/client_manager_bottom_section.dart';
import 'package:crm/page/ClientManager/add_client_page.dart';
import 'package:crm/view/AppBar/custom_app_bar.dart';

const String Title = '客户关系管理（CRM）';

class ClientManagerPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _ClientManagerPageState();
}

class _ClientManagerPageState extends State<ClientManagerPage>
    with SingleTickerProviderStateMixin {
  List<String> _tabBarTitles = ['我的客户', '潜在客户'];
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: _tabBarTitles.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final clientManagerScopedModel = MainModel().of(context);
    return Scaffold(
      backgroundColor: AppColors.PageBackgroundColor,
      appBar: CustomAppBar(
        title: Title,
      ),
      body: SafeArea(
        child: Column(
          children: <Widget>[
            ClientManagerTabsSection(
              tabController: _tabController,
              tabTitles: _tabBarTitles,
              changeListStyle: () {
                clientManagerScopedModel.changeClientManagerListStyle(
                    !clientManagerScopedModel.clientManagerListIsArrangement);
                if (!mounted) return;
                setState(() {});
              },
            ),
            ClientManagerListViewSection(
              tabController: _tabController,
              tabTitles: _tabBarTitles,
            ),
            ClientManagerBottomSection(
              addClientAction: () {
                print('添加客户');
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => AddClientPage(
                          clientType: 0,
                        ),
                  ),
                );
              },
              addLatencyClientAction: () {
                print('添加潜在客户');
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => AddClientPage(
                          clientType: 1,
                        ),
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
